home *** CD-ROM | disk | FTP | other *** search
/ ADA Programming Guide / ADA Programming Guide.iso / ada_gwu / axqw.c < prev    next >
C/C++ Source or Header  |  1996-01-30  |  3KB  |  117 lines

  1. /*
  2.  * Copyright (C) 1985-1992  New York University
  3.  * 
  4.  * This file is part of the Ada/Ed-C system.  See the Ada/Ed README file for
  5.  * warranty (none) and distribution info and also the GNU General Public
  6.  * License for more details.
  7.  
  8.  */
  9. /* axqw.c - axq output procedures */
  10.  
  11. #define GEN
  12.  
  13. #include "hdr.h"
  14. #include "vars.h"
  15. #include "segment.h"
  16. #include "gvars.h"
  17. #include "slot.h"
  18. #include "ifile.h"
  19. #include "setp.h"
  20. #include "libfp.h"
  21. #include "miscp.h"
  22. #include "segmentp.h"
  23. #include "axqwp.h"
  24.  
  25. static void put_slot(IFILE *, Tuple);
  26.  
  27. void segment_write(IFILE *file, Segment seg)                /*;segment_write*/
  28. {
  29.     short    dim;
  30.  
  31.     seg_check(seg);
  32.     putnum(file, "segment-kind", seg->seg_kind);
  33.     dim = seg->seg_maxpos + 1;
  34.     putnum(file, "segment-dim", dim);
  35.     fwrite(seg->seg_data, seg->seg_size, dim, file->fh_file);
  36. }
  37.  
  38. void put_cde_slots(IFILE *file, int ifaxq)                    /*;put_cde_slots*/
  39. {
  40.     long    dpos;
  41.  
  42.     dpos = iftell(file); /* get current position */
  43.     putnum(file, "n-code_slots", tup_size(CODE_SLOTS));
  44.     putnum(file, "n-data-slots", tup_size(DATA_SLOTS));
  45.     putnum(file, "n-exception-slots", tup_size(EXCEPTION_SLOTS));
  46.     put_slot(file, CODE_SLOTS);
  47.     put_slot(file, DATA_SLOTS);
  48.     put_slot(file, EXCEPTION_SLOTS);
  49.     /* now replace word at start of  file with long giving offset to 
  50.      *start of information just written.
  51.      */
  52.     file->fh_slots = dpos;
  53.     ifclose(file);
  54. }
  55.  
  56. static void put_slot(IFILE *file, Tuple tup)                    /*;put_slot*/
  57. {
  58.     /* This procedure writes out the SLOTS information. These are maps from
  59.      * symbols to unit names. The interpreter needs only to know the names
  60.      * of the symbols so we write their names if available, else
  61.      * an empty string.
  62.      */
  63.  
  64.     int i, n;
  65.     Slot slot;
  66.  
  67.     n = tup_size(tup);
  68.     putnum(file, "slot-entries", n);
  69.     for (i = 1; i <= n; i++) {
  70.         slot = (Slot) tup[i];
  71.         if (slot == (Slot)0) {
  72.             if (compiling_predef)
  73.                 chaos("undefined slot compiling predef");
  74.             putnum(file, "slot-exists", 0);
  75.         }
  76.         else {
  77.             putnum(file, "slot-exists", 1);
  78.             putnum(file, "slot-seq", slot->slot_seq);
  79.             putnum(file, "slot-unit", slot->slot_unit);
  80.             putnum(file, "slot-number", slot->slot_number);
  81.             putstr(file, "slot-name", slot->slot_name);
  82. #ifdef MONITOR
  83.             putstr(file, "slot-file", slot->slot_file);
  84.             putstr(file, "slot-package", slot->slot_package);
  85. #endif
  86.         }
  87.     }
  88. }
  89.  
  90. void predef_exceptions(Tuple tup)                    /*;predef_exceptions*/
  91. {
  92.     /* This procedure writes out the SLOTS information.
  93.      * This variant of put_slot writes out definitions of predefined exceptions
  94.      * when compiling predef, in a form suitable for inclusion as the body
  95.      * of init_predef_exceptions (cf. init.c).
  96.      */
  97.  
  98.     int i, n;
  99.     Slot slot;
  100.  
  101.     n = tup_size(tup);
  102.     printf("exception slots\n");
  103.     /* first five exceptions defined in standard */
  104.     for (i = 6; i <= n; i++) {
  105.         slot = (Slot) tup[i];
  106.         if (slot == (Slot)0) {
  107.             if (compiling_predef)
  108.                 chaos("undefined slot compiling predef");
  109.         }
  110.         else {
  111.             printf("    init_predef_exception(%d, %d, %d, \"%s\");\n",
  112.               slot->slot_seq, slot->slot_unit, slot->slot_number,
  113.               slot->slot_name);
  114.         }
  115.     }
  116. }
  117.